using System;
using System.Drawing;
using System.Collections;
using System.Windows.Forms;
using System.Data;

namespace FloodWarnSmartPhone
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class Form1 : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label lblHeight;
		private System.Windows.Forms.MainMenu mainMenu1;
		private System.Windows.Forms.MenuItem mnuUpdate;
		private System.Windows.Forms.MenuItem menuItem1;
		private System.Windows.Forms.MenuItem mnuMenuUpdate;
		private System.Windows.Forms.Label lblFlow;
		private System.Windows.Forms.Label lblDateTime;
		private System.Windows.Forms.Label lblPercent;
		private System.Windows.Forms.MenuItem mnuMenuAbout;
		private System.Windows.Forms.MenuItem mnuMenuExit;
		private System.Windows.Forms.Label lblStatus;
		net.galos.www.Scrape objScrape = new net.galos.www.Scrape();

		public Form1()
		{
			InitializeComponent();
		}
		protected override void Dispose( bool disposing )
		{
			base.Dispose( disposing );
		}
		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
            this.mainMenu1 = new System.Windows.Forms.MainMenu();
            this.mnuUpdate = new System.Windows.Forms.MenuItem();
            this.menuItem1 = new System.Windows.Forms.MenuItem();
            this.mnuMenuUpdate = new System.Windows.Forms.MenuItem();
            this.mnuMenuAbout = new System.Windows.Forms.MenuItem();
            this.mnuMenuExit = new System.Windows.Forms.MenuItem();
            this.lblHeight = new System.Windows.Forms.Label();
            this.lblFlow = new System.Windows.Forms.Label();
            this.lblDateTime = new System.Windows.Forms.Label();
            this.lblPercent = new System.Windows.Forms.Label();
            this.lblStatus = new System.Windows.Forms.Label();
            this.SuspendLayout();
            // 
            // mainMenu1
            // 
            this.mainMenu1.MenuItems.Add(this.mnuUpdate);
            this.mainMenu1.MenuItems.Add(this.menuItem1);
            // 
            // mnuUpdate
            // 
            this.mnuUpdate.Text = "Update";
            this.mnuUpdate.Click += new System.EventHandler(this.menuItem1_Click);
            // 
            // menuItem1
            // 
            this.menuItem1.MenuItems.Add(this.mnuMenuUpdate);
            this.menuItem1.MenuItems.Add(this.mnuMenuAbout);
            this.menuItem1.MenuItems.Add(this.mnuMenuExit);
            this.menuItem1.Text = "Menu";
            // 
            // mnuMenuUpdate
            // 
            this.mnuMenuUpdate.Text = "Update";
            this.mnuMenuUpdate.Click += new System.EventHandler(this.mnuMenuUpdate_Click);
            // 
            // mnuMenuAbout
            // 
            this.mnuMenuAbout.Text = "About";
            this.mnuMenuAbout.Click += new System.EventHandler(this.mnuUpdateAbout_Click);
            // 
            // mnuMenuExit
            // 
            this.mnuMenuExit.Text = "Exit";
            this.mnuMenuExit.Click += new System.EventHandler(this.mnuUpdateExit_Click);
            // 
            // lblHeight
            // 
            this.lblHeight.Location = new System.Drawing.Point(0, 48);
            this.lblHeight.Name = "lblHeight";
            this.lblHeight.Size = new System.Drawing.Size(170, 24);
            this.lblHeight.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // lblFlow
            // 
            this.lblFlow.Location = new System.Drawing.Point(0, 24);
            this.lblFlow.Name = "lblFlow";
            this.lblFlow.Size = new System.Drawing.Size(170, 24);
            this.lblFlow.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // lblDateTime
            // 
            this.lblDateTime.Location = new System.Drawing.Point(0, 0);
            this.lblDateTime.Name = "lblDateTime";
            this.lblDateTime.Size = new System.Drawing.Size(170, 24);
            this.lblDateTime.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // lblPercent
            // 
            this.lblPercent.Location = new System.Drawing.Point(0, 72);
            this.lblPercent.Name = "lblPercent";
            this.lblPercent.Size = new System.Drawing.Size(170, 24);
            this.lblPercent.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // lblStatus
            // 
            this.lblStatus.ForeColor = System.Drawing.Color.Red;
            this.lblStatus.Location = new System.Drawing.Point(0, 152);
            this.lblStatus.Name = "lblStatus";
            this.lblStatus.Size = new System.Drawing.Size(168, 22);
            // 
            // Form1
            // 
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
            this.ClientSize = new System.Drawing.Size(240, 266);
            this.Controls.Add(this.lblStatus);
            this.Controls.Add(this.lblPercent);
            this.Controls.Add(this.lblDateTime);
            this.Controls.Add(this.lblFlow);
            this.Controls.Add(this.lblHeight);
            this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
            this.Menu = this.mainMenu1;
            this.Name = "Form1";
            this.Text = "Snoqualmie FloodWarn";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.ResumeLayout(false);

		}
		#endregion

		static void Main() 
		{
			Application.Run(new Form1());
		}

		private void UpdateData()
		{
			lblStatus.Text = "Connecting...";
			// display the wait cursor
			Cursor.Current = Cursors.WaitCursor;
			mnuUpdate.Enabled=false;

			try
			{

				bool sCommOK = objScrape.SnoScrape();
//				string sFullText = objScrape.GetFullText();

				lblStatus.Text = "Getting Date of data";
				string sDate = objScrape.GetLatestDate();
				lblStatus.Text = "Getting Time of data";
				string sTime = objScrape.GetLatestTime();
				lblDateTime.Text = sDate + " " + sTime;

				lblStatus.Text = "Getting Height";
				string sHeight = objScrape.GetLatestHeightStr().Trim()+" Feet Deep";
				if (sHeight=="") sHeight="n/a";
				lblHeight.Text = sHeight;

				lblStatus.Text = "Getting Flow";
				string sFlow = objScrape.GetLatestFlowStr().Trim()+" Cubic Feet/Second";
				if (sFlow == "") sFlow = "n/a";
				lblFlow.Text = sFlow;

				lblStatus.Text = "Getting Percent Full";
				string sPercentHeight = objScrape.GetHeightPercent().ToString()+"% Full";
				if (sPercentHeight == "-500%") sPercentHeight = "n/a";
				lblPercent.Text = sPercentHeight;
				lblStatus.Text="";
				// display the default cursor
				Cursor.Current = Cursors.Default;
				mnuUpdate.Enabled=true;



				//				double dblFlow = objScrape.GetLatestFlow();
				//				double dblHeight = objScrape.GetLatestHeight();
			}
			catch(Exception e)
			{
				lblDateTime.Text = "Data not available";
				lblFlow.Text = "Check your cell coverage";
				lblHeight.Text = "and try again";
				lblPercent.Text = e.Message.ToString();

				// display the default cursor
				Cursor.Current = Cursors.Default;
				mnuUpdate.Enabled=true;

			}


		}

		private void mnuMenuUpdate_Click(object sender, System.EventArgs e)
		{
			UpdateData();
		}
		private void mnuUpdateAbout_Click(object sender, System.EventArgs e)
		{
			lblDateTime.Text = "Snoqualmie Floodwarn";
			lblFlow.Text = "Version 0.2";
			lblHeight.Text = "Copyright 2003-2010";
			lblPercent.Text = "Mike Galos";
		}

		private void mnuUpdateExit_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		
		}


		private void Form1_Load(object sender, System.EventArgs e)
		{
            lblDateTime.Text = "Snoqualmie Floodwarn";
            lblFlow.Text = "Version 0.2";
            lblHeight.Text = "Copyright 2003-2010";
            lblPercent.Text = "Mike Galos";
        }

		private void menuItem1_Click(object sender, System.EventArgs e)
		{
			UpdateData();
		}

	}
}
